package com.dc.controller;

import com.dc.annotation.Log;
import com.dc.common.ResponseResultVO;
import com.dc.entity.ro.FireWorkOrderRO;
import com.dc.entity.vo.FireVO;
import com.dc.service.WorkOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

import static com.dc.common.ResponseResultVO.checkParameterIsNotNull;

@Api(tags = "运维平台-工单管理")
@RestController
@RequestMapping("/workOrder")
public class WorkOrderController {

    @Resource
    private WorkOrderService workOrderService;

    @Log(title = "工单管理", businessDesc = "增加自定义类型工单")
    @ApiOperation(value = "增加", notes = "增加")
    @PostMapping("/insertWorkOrder")
    public ResponseResultVO insertFireWorkOrder(@RequestBody FireWorkOrderRO ro) {
        return workOrderService.insertWorkOrder(ro);
    }

    // 暂时废弃
    /*@Log(title = "工单管理", businessDesc = "修改工单")
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/updateWorkOrder")
    public ResponseResultVO updateFireWorkOrder(@RequestBody FireWorkOrderRO ro) {
        return workOrderService.updateWorkOrder(ro);
    }*/

    @Log(title = "工单管理", businessDesc = "删除工单")
    @ApiOperation(value = "删除", notes = "删除")
    @GetMapping("/deleteWorkOrder")
    public ResponseResultVO deleteFireWorkOrder(@RequestParam String id) {
        checkParameterIsNotNull(id, "id不能为空");
        List<String> idList = Arrays.asList(id.split(","));
        return ResponseResultVO.successResult(workOrderService.removeByIds(idList));
    }

    @ApiOperation(value = "查询列表", notes = "查询列表")
    @PostMapping("/selectWorkOrderList")
    public ResponseResultVO<FireVO> selectWorkOrderList(@RequestBody FireWorkOrderRO ro) {
        return workOrderService.selectWorkOrderList(ro);
    }

    @ApiOperation(value = "查询详情", notes = "查询详情")
    @GetMapping("/selectWorkOrderInfo/{id}")
    public ResponseResultVO<FireVO> selectWorkOrderInfo(@PathVariable String id) {
        return ResponseResultVO.successResult(workOrderService.getById(id));
    }

    @ApiOperation(value = "类型数量统计", notes = "类型数量统计")
    @GetMapping("/selectTypeNumber")
    public ResponseResultVO selectWorkOrderInfo() {
        return workOrderService.selectTypeNumber();
    }


}
